home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
8bit
/
cislib_b
/
sort.doc
< prev
next >
Wrap
Text File
|
1995-04-22
|
5KB
|
199 lines
SORT
SORT is a high performance in-RAM
ACTION! sorting FUNCtion. It is
restricted to fixed length entries
with a single key, although the key
can be any length and located
anywhere within the entry. SORT
features compact size and great
flexibility, while being very easy to
use.
TYPICAL PERFORMANCE (SECONDS)
**********************************
* Length:| 8 | 32 | 128| 512*
**********************************
* 32 Entries|0.05|0.12|0.37|1.40*
*------------+----+----+----+----*
* 64 Entries|0.13|0.30|1.00|3.77*
*------------+----+----+----+----*
* 128 Entries|0.32|0.77|2.60| N/A*
*------------+----+----+----+----*
* 256 Entries|0.77|1.90|6.45| N/A*
*------------+----+----+----+----*
* 512 Entries|1.85|4.58| N/A| N/A*
*------------+----+----+----+----*
*1024 Entries|4.53|11.4| N/A| N/A*
*------------+----+----+----+----*
*2048 Entries|10.8| N/A| N/A| N/A*
*------------+----+----+----+----*
*4096 Entries|25.8| N/A| N/A| N/A*
**********************************
(All timings for SORT are the
arithmetic mean of 16 runs with fully
random numeric data, sorting on the
entire entry, with display DMA
enabled in TEXT MODE 0. Timings are
to the nearest 1/60 second using the
ATARI Real-Time CLOcK. Performance
may be significantly improved or
degraded with non-random data and/or
different display DMA.)
COMPARISON TO SUPERSORT
(APX-20030)
As compared to "SUPERSORT", SORT
has several major advantages,
particularly for the ACTION! user,
and only two disadvantages. The
first disadvantage is slight:
although SORT is quite fast,
apparently it is a little bit slower
than "SUPERSORT". (Whereas
"SUPERSORT" claims to sort 1000
thirty-byte entries in "less than ten
seconds", SORT will typically take
about 10.5 seconds. For 1000
one-byte entries, the comparison is
"less than two seconds" versus
typically about 2.27 seconds. But
see timing note above.) The second
disadvantage is that SORT is limited
to sorting on a single key (although
that key may be located anywhere in
the entry and may be of any length),
whereas "SUPERSORT" can handle
multiple keys.
On the other hand, the advantages
of SORT are several:
1. About one-third the storage
requirement. (356 bytes versus
"about" 1000 bytes, plus no use of
RAM page 6 - see #4 below)
2. Does not use "AUTORUN.SYS" or
install itself automatically.
Instead, SORT is an ACTION! FUNCtion
which may be INCLUDEd from a library.
(This frees "AUTORUN.SYS" for other
purposes, saves precious RAM, and
prevents conflict with use of the
ATARI 850 Interface Module.)
3. Error checking to prevent
inadvertant RAM alteration.
4. No use of page 6 in memory.
(Instead, SORT uses only the floating
point work area $D4-$DF and the 6502
stack, saving page 6 for other
purposes).
5. "Unlimited" entry length
(versus 256 bytes).
6. "Unlimited" number of entries
(versus 10000).
7. No POKE statements required.
(All parameters are passed by the
ACTION! FUNCtion call.)
IMPORTANT NOTES
1. Since the location of the sort
key may be anywhere in the entry, it
is possible to sort the same data
again in a different sequence.
2. For equal keys, SORT does NOT
preserve the original entry sequence
(so it WON'T work for successive
sorts on separate minor to major keys
- you must sort on a single composite
key).
CALLING
BYTE FUNC Sort(CARD KPOS, KLEN, ELEN,
DLEN, BYTE POINTER DADR)
KPOS: The position of the most
significant byte of the sort key
within the entry. (The first
position of the entry is 0.)
KLEN: Length of the sort key.
ELEN: Length of individual entries
within the array (or block of RAM).
DLEN must be evenly divisible by
ELEN!
DLEN: Length of the array (or
block of RAM).
DADR: Address of the array (or
block of RAM) containing all of the
data to be sorted.
RETURN CODE
SORT returns 0 if the sort was
successful, 1 if the parameters were
in error.
ALGORITHM
SORT is a 6502 machine language
adaptation of the shell sort
algorithm as discussed by D. E. Knuth
in "The Art of Computer Programming,
Vol. 3: Sorting and Searching"
(Addison-Wesley, Reading, Mass.,
1973).
DEMONSTRATION
The following ACTION! program will
read in a list of typed names, sort
them into alphabetical order, and
then display them on the screen:
INCLUDE "SORT.ACT"
PROC DEMO()
BYTE ARRAY X(1000), ;50 X 20 BYTES
S(21) ;I/O BUFFER
INT I,J
PRINTE("BLANK LINE TO END.")
FOR I=0 TO 1000-20 STEP 20
DO
PRINT("NAME: ")
INPUTMD(0,S,20)
IF S(0)=0 THEN EXIT
ELSEIF S(0)<20 THEN
SETBLOCK(S+S(0)+1,20-S(0),' )
FI
MOVEBLOCK(X+I,S+1,20)
OD
IF SORT(0,20,20,I,X) THEN
PRINTE("SORT ERROR!") BREAK() FI
FOR J=0 TO I-20 STEP 20
DO
MOVEBLOCK(S+1,X+J,20)
S(0)=20
PRINTE(S)
OD
RETURN